package com.qf.hospital.service.impl;

import com.qf.hospital.VO.DoctorVO;
import com.qf.hospital.entity.Doctor;
import com.qf.hospital.entity.DoctorExample;
import com.qf.hospital.mapper.DoctorMapper;
import com.qf.hospital.service.DoctorService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/10/19 20:28
 */

@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper mapper;

    /**
     * 根据星期查找排班信息
     * @param week
     * @return
     */
    @Override
    public List<Map<String, String>> findSchedulerByWeek(String week) {
        List<String> doctorNameList = mapper.findSchedulerByWeek(week);

        //封装数据
        List<Map<String, String>> data = new ArrayList<>();
        for (String doctorName : doctorNameList) {
            Map<String, String> map = new HashMap<>();
            map.put("doctorName", doctorName);
            data.add(map);
        }
        return data;
    }

    /**
     * 根据条件查询医生信息
     * @param registeredId
     * @param departmentId
     * @return
     */
    @Override
    public List<DoctorVO> findDoctorByRegisterdIdAndDepartmentId(Integer registeredId, Integer departmentId) {
        DoctorExample example = new DoctorExample();
        example.createCriteria().andRegisteredIdEqualTo(registeredId).andDepartmentIdEqualTo(departmentId);
        List<Doctor> doctorList = mapper.selectByExample(example);
        //封装
        List<DoctorVO> data = new ArrayList<>();
        for (Doctor doctor : doctorList) {
            DoctorVO doctorVO = new DoctorVO();
            BeanUtils.copyProperties(doctor, doctorVO);
            data.add(doctorVO);
        }
        return data;
    }
}
